package com.wrb.customer.controller.microservice;

import com.wrb.customer.model.Customer;
import com.wrb.customer.response.ResponseCode;
import com.wrb.customer.response.ServerResponse;
import com.wrb.customer.service.CustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author Wrb
 * @date 2019/12/20 16:10
 */
@RestController
@RequestMapping("/micro/customer")
@CrossOrigin(origins = "*", methods = {RequestMethod.POST, RequestMethod.GET})
@Api(tags = "会员服务内部调用")
public class MicroCustomerController {

	@Autowired
	private CustomerService customerService;

	@RequestMapping(value = "/get", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	@ApiOperation(value = "获取用户信息")
	public ResponseEntity get(
			@ApiParam(required = true, value = "会员id") @RequestParam(required = true) long customerId
	) {
		Customer customer = customerService.selectCustomer(customerId);
		if (customer == null) {
			return ServerResponse.error(ResponseCode.CUSTOMER_NOT_FOUND, "用户找不到");
		}
		return ServerResponse.success(customer);
	}
}
